using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQPZUORD
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                case "YGR":
                case "YCC":
                case "TST":
                default:
                    #region=========
                    dwReturn["VAAMANDANT"] = "00";
                    dwReturn["VAAKOLL"] = "     ";
                    dwReturn["VAAART"] = "                        ";
                    dwReturn["VAAKURZBEZ"] = "     ";
                    dwReturn["VAABEZ"] = "                              ";
                    dwReturn["VAASPERRDAT"] = "0";
                    dwReturn["VAABESTANDF"] = "J";
                    dwReturn["VAAMEBRT"] = "   ";
                    dwReturn["VAABRTFKT"] = "000000000000";
                    dwReturn["VAABRTVON"] = "0";
                    dwReturn["VAABRTBIS"] = "0";
                    dwReturn["VAAMELAE"] = "   ";
                    dwReturn["VAALAEFKT"] = "000000000000";
                    dwReturn["VAALAEVON"] = "0";
                    dwReturn["VAALAEBIS"] = "0";
                    dwReturn["VAAMEHRAP"] = "   ";
                    dwReturn["VAAHRAPVON"] = "0";
                    dwReturn["VAAHRAPBIS"] = "0";
                    dwReturn["VAAMEBRAP"] = "   ";
                    dwReturn["VAABRAPVON"] = "0";
                    dwReturn["VAABRAPBIS"] = "0";
                    dwReturn["VAAMEGEW"] = "   ";
                    dwReturn["VAAGEWGRP"] = " ";
                    dwReturn["VAAGEWFKT"] = "000000000000";
                    dwReturn["VAAGEWVON"] = "0";
                    dwReturn["VAAGEWBIS"] = "0";
                    dwReturn["VAAMENGEH"] = "   ";
                    dwReturn["VAAMEGGRP"] = " ";
                    dwReturn["VAAMEGFKT"] = "000000000000";
                    dwReturn["VAAMEUEB"] = "   ";
                    dwReturn["VAAUEBGRP"] = " ";
                    dwReturn["VAAUEBFKT"] = "000000000000";
                    dwReturn["VAAEAN"] = "0000000000000";
                    dwReturn["VAASTATWNR"] = "            ";
                    dwReturn["VAAZOLLTNR1"] = "                    ";
                    dwReturn["VAAZOLLTNR2"] = "                    ";
                    dwReturn["VAAARTPRGR"] = "   ";
                    dwReturn["VAAPVGRP"] = "   ";
                    dwReturn["VAAAUFART"] = "   ";
                    dwReturn["VAAPACKART"] = "   ";
                    dwReturn["VAAURLAND"] = "   ";
                    dwReturn["VAAWECHSEL"] = " ";
                    dwReturn["VAAURTEXT"] = "         ";
                    dwReturn["VAAREFART"] = "                        ";
                    dwReturn["VAAPART"] = "                    ";
                    dwReturn["VAADKUNDNR"] = "00000000";
                    dwReturn["VAADWERK"] = "   ";
                    dwReturn["VAADABT"] = "   ";
                    dwReturn["VAADART"] = "                    ";
                    dwReturn["VAADVAR"] = "  ";
                    dwReturn["VAAGESANT1"] = "000";
                    dwReturn["VAAGESBEZ1"] = "      ";
                    dwReturn["VAAPOLANT1"] = "000";
                    dwReturn["VAAPOLBEZ1"] = "      ";
                    dwReturn["VAARUECKANT1"] = "000";
                    dwReturn["VAARUECKBEZ1"] = "      ";
                    dwReturn["VAAGESANT2"] = "000";
                    dwReturn["VAAGESBEZ2"] = "      ";
                    dwReturn["VAAPOLANT2"] = "000";
                    dwReturn["VAAPOLBEZ2"] = "      ";
                    dwReturn["VAARUECKANT2"] = "000";
                    dwReturn["VAARUECKBEZ2"] = "      ";
                    dwReturn["VAAGESANT3"] = "000";
                    dwReturn["VAAGESBEZ3"] = "      ";
                    dwReturn["VAAPOLANT3"] = "000";
                    dwReturn["VAAPOLBEZ3"] = "      ";
                    dwReturn["VAARUECKANT3"] = "000";
                    dwReturn["VAARUECKBEZ3"] = "      ";
                    dwReturn["VAAGESANT4"] = "000";
                    dwReturn["VAAGESBEZ4"] = "      ";
                    dwReturn["VAAPOLANT4"] = "000";
                    dwReturn["VAAPOLBEZ4"] = "      ";
                    dwReturn["VAARUECKANT4"] = "000";
                    dwReturn["VAARUECKBEZ4"] = "      ";
                    dwReturn["VAAGESANT5"] = "000";
                    dwReturn["VAAGESBEZ5"] = "      ";
                    dwReturn["VAAPOLANT5"] = "000";
                    dwReturn["VAAPOLBEZ5"] = "      ";
                    dwReturn["VAARUECKANT5"] = "000";
                    dwReturn["VAARUECKBEZ5"] = "      ";
                    dwReturn["VAAGESANT6"] = "000";
                    dwReturn["VAAGESBEZ6"] = "      ";
                    dwReturn["VAAPOLANT6"] = "000";
                    dwReturn["VAAPOLBEZ6"] = "      ";
                    dwReturn["VAARUECKANT6"] = "000";
                    dwReturn["VAARUECKBEZ6"] = "      ";
                    dwReturn["VAAGESANT7"] = "000";
                    dwReturn["VAAGESBEZ7"] = "      ";
                    dwReturn["VAAPOLANT7"] = "000";
                    dwReturn["VAAPOLBEZ7"] = "      ";
                    dwReturn["VAARUECKANT7"] = "000";
                    dwReturn["VAARUECKBEZ7"] = "      ";
                    dwReturn["VAAGESANT8"] = "000";
                    dwReturn["VAAGESBEZ8"] = "      ";
                    dwReturn["VAAPOLANT8"] = "000";
                    dwReturn["VAAPOLBEZ8"] = "      ";
                    dwReturn["VAARUECKANT8"] = "000";
                    dwReturn["VAARUECKBEZ8"] = "      ";
                    dwReturn["VAAHWANT"] = "      ";
                    dwReturn["VAAPOLANTG"] = "0";
                    dwReturn["VAARUEKANTG"] = "0";
                    dwReturn["VAAAENDZL"] = "0";
                    dwReturn["VAAAENDBEN"] = "        ";
                    dwReturn["VAAAENDDAT"] = "0";
                    dwReturn["VAANEUBEN"] = "        ";
                    dwReturn["VAANEUDAT"] = "0";
                    dwReturn["VAAARTST"] = "G";
                    dwReturn["VAAZUREGEL"] = " ";
                    dwReturn["VAAZIELGR"] = "    ";
                    dwReturn["VAAPRGR"] = "K  ";
                    dwReturn["VAAARTGRP"] = "R  ";
                    dwReturn["VAALO"] = "  ";
                    dwReturn["VAABRTCA"] = "N";
                    dwReturn["VAALAECA"] = "N";
                    dwReturn["VAAHRAPCA"] = " ";
                    dwReturn["VAABRAPCA"] = " ";
                    dwReturn["VAAGEWCA"] = "N";
                    dwReturn["VAAPREH"] = "   ";
                    dwReturn["VAAEXCL"] = " ";
                    dwReturn["VAATAX"] = "   ";
                    dwReturn["VAASONDER"] = " ";
                    dwReturn["VAALASCHE"] = " ";
                    dwReturn["VAAFARBKZ"] = " ";
                    dwReturn["VAAWEBLEV"] = "0";
                    dwReturn["VAAARTFAMFL"] = " ";
                    dwReturn["VAAARTFAM"] = "                        ";
                    dwReturn["VAAARTWEB"] = "                        ";
                    dwReturn["VAAWEBSTD"] = " ";
                    dwReturn["VAAARTCOL"] = "          ";
                    dwReturn["VAAARTFIN"] = "          ";
                    dwReturn["VAADIMAM"] = "  ";
                    dwReturn["VAADIMZAM"] = "  ";
                    dwReturn["VAADIMLG"] = "  ";
                    dwReturn["VAAKONFDES"] = " ";
                    dwReturn["VAAKONFRAP"] = " ";
                    dwReturn["VAAKONFCOL"] = " ";
                    dwReturn["VAAKONFLG"] = " ";
                    dwReturn["VAAKONFBRT"] = " ";
                    dwReturn["VAAKONFMRK"] = "   ";
                    dwReturn["VAABUSIMODE"] = "   ";
                    dwReturn["VAAALTERNAT"] = " ";
                    dwReturn["VAAARTDESS"] = "          ";
                    dwReturn["VAAARTSIZE"] = "       ";
                    dwReturn["VAADIMF1"] = "          ";
                    dwReturn["VAADIMF2"] = "          ";
                    dwReturn["VAADIMF3"] = "          ";
                    dwReturn["VAAFILLER"] = "                                                                         ";
                    #endregion
                    break;
            }
        }
        public void MapQPZUORD(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQPZUORD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQPZUORD(dwData, 3);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQPZUORD(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertQPZUORD(dwLocal);
            }
            UpdateQPZUORD(dwLocal);
        }
        public void InsertQPZUORD(DataRow dwData, string ITXDBVERSION = "50.24")
        {


            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO QPZUORD(QPZMANDANT, QPZARTST, QPZKUNDNR, QPZWERK, QPZABT, QPZART, QPZVAR, QPZPNRKRS, QPZPLFDNR, QPZAENZL, QPZAENB, QPZAEND, QPZNEUB, QPZNEUD, QPZSPEZIF, QPZSPSTA, QPZSPGRD, QPZZUSTAND, QPZPKUNDNR, QPZPADRSL, QPZLIEFNR, QPZLAFDL, QPZLADS, QPZFKZ, QPZAUFBER, QPZDRTRB, QPZFILLER)"
                                + " VALUES (:QPZMANDANT,:QPZARTST, '00000000', '   ', '   ',:QPZART, :QPZVAR, :QPZPNRKRS,:QPZPLFDNR, 0, '        ', 0, :QPZNEUB, :QPZNEUD,:QPZSPEZIF, 'N', '                              ', '    ', '        ', '        ', '        ', '        ', '        ', '  ', '  ', '     ', '            ')";
            or1.Parameters.Add("QPZMANDANT", OracleType.NVarChar).Value = dwData["QPZMANDANT"].ToString();
            or1.Parameters.Add("QPZARTST", OracleType.NVarChar).Value = dwData["QPZARTST"].ToString();
            or1.Parameters.Add("QPZART", OracleType.NVarChar).Value = dwData["QPZART"].ToString();
            or1.Parameters.Add("QPZVAR", OracleType.NVarChar).Value = dwData["QPZVAR"].ToString();
            or1.Parameters.Add("QPZPNRKRS", OracleType.NVarChar).Value = dwData["QPZPNRKRS"].ToString();
            or1.Parameters.Add("QPZPLFDNR", OracleType.NVarChar).Value = dwData["QPZPLFDNR"].ToString();
            or1.Parameters.Add("QPZNEUB", OracleType.NVarChar).Value = dwData["QPZNEUB"].ToString();
            or1.Parameters.Add("QPZNEUD", OracleType.NVarChar).Value = dwData["QPZNEUD"].ToString();
            or1.Parameters.Add("QPZSPEZIF", OracleType.NVarChar).Value = dwData["QPZSPEZIF"].ToString();
            Connect2Proxy(or1);
        }
        public void DeleteQPZUORD(string client, string stage, string art, string var)
        {
            OracleCommand or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE QPZUORD "
                        + " WHERE QPZMANDANT=:QPZMANDANT  AND QPZARTST=:QPZARTST AND QPZART=:QPZART  AND QPZVAR=:QPZVAR";
            or1.Parameters.Add("QPZMANDANT", OracleType.NVarChar).Value = client;
            or1.Parameters.Add("QPZARTST", OracleType.NVarChar).Value = stage;
            or1.Parameters.Add("QPZART", OracleType.NVarChar).Value = art;
            or1.Parameters.Add("QPZVAR", OracleType.NVarChar).Value = var;
            Connect2Proxy(or1);
        }
        public DataSet QueryQPZUORD(DataRow dwData, int option = 1)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();

            OracleCommand or1;

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT* FROM QPZUORD"
                        + " WHERE  QPZARTST='F' AND QPZART=:QPZART AND QPZVAR=:QPZVAR";
                    or1.Parameters.Add("QPZART", OracleType.NVarChar).Value = dwData["QPZART"].ToString();
                    or1.Parameters.Add("QPZVAR", OracleType.NVarChar).Value = dwData["QPZVAR"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT* FROM QPZUORD"
                        + " WHERE QPZMANDANT=:QPZMANDANT AND QPZARTST='F' AND QPZPNRKRS=:QPZPNRKRS AND QPZPLFDNR=:QPZPLFDNR";
                    or1.Parameters.Add("QPZMANDANT", OracleType.NVarChar).Value = dwData["QPZMANDANT"].ToString();
                    or1.Parameters.Add("QPZPNRKRS", OracleType.NVarChar).Value = dwData["QPZPNRKRS"].ToString();
                    or1.Parameters.Add("QPZPLFDNR", OracleType.NVarChar).Value = dwData["QPZPLFDNR"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT* FROM QPZUORD"
                        + " WHERE QPZMANDANT=:QPZMANDANT AND QPZARTST='F' AND QPZART=:QPZART AND QPZVAR=:QPZVAR AND QPZPNRKRS=:QPZPNRKRS AND QPZPLFDNR=:QPZPLFDNR";
                    or1.Parameters.Add("QPZMANDANT", OracleType.NVarChar).Value = dwData["QPZMANDANT"].ToString();
                    or1.Parameters.Add("QPZART", OracleType.NVarChar).Value = dwData["QPZART"].ToString();
                    or1.Parameters.Add("QPZVAR", OracleType.NVarChar).Value = dwData["QPZVAR"].ToString();
                    or1.Parameters.Add("QPZPNRKRS", OracleType.NVarChar).Value = dwData["QPZPNRKRS"].ToString();
                    or1.Parameters.Add("QPZPLFDNR", OracleType.NVarChar).Value = dwData["QPZPLFDNR"].ToString();
                    break;
                default:
                    or1.CommandText = "SELECT* FROM QPZUORD"
                        + " WHERE  QPZARTST='F' AND QPZART=:QPZART AND QPZVAR=:QPZVAR";
                    or1.Parameters.Add("QPZART", OracleType.NVarChar).Value = dwData["QPZART"].ToString();
                    or1.Parameters.Add("QPZVAR", OracleType.NVarChar).Value = dwData["QPZVAR"].ToString();
                    break;
            }

            SResult = Connect2Proxy(or1);
            if (SResult.Tables.Count > 0)
            {
                SResult.Tables[0].TableName = "QPZUORD";
                SReturn.Merge(SResult);
            }
            return SReturn;
        }
        public void UpdateQPZUORD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE QPZUORD SET "
                + "QPZMANDANT=:QPZMANDANT,"
                + "QPZARTST=:QPZARTST,"
                + "QPZKUNDNR=:QPZKUNDNR,"
                + "QPZWERK=:QPZWERK,"
                + "QPZABT=:QPZABT,"
                + "QPZART=:QPZART,"
                + "QPZVAR=:QPZVAR,"
                + "QPZPNRKRS=:QPZPNRKRS,"
                + "QPZPLFDNR=:QPZPLFDNR,"
                + "QPZAENZL=:QPZAENZL,"
                + "QPZAENB=:QPZAENB,"
                + "QPZAEND=:QPZAEND,"
                + "QPZNEUB=:QPZNEUB,"
                + "QPZNEUD=:QPZNEUD,"
                + "QPZSPEZIF=:QPZSPEZIF,"
                + "QPZSPSTA=:QPZSPSTA,"
                + "QPZSPGRD=:QPZSPGRD,"
                + "QPZZUSTAND=:QPZZUSTAND,"
                + "QPZPKUNDNR=:QPZPKUNDNR,"
                + "QPZPADRSL=:QPZPADRSL,"
                + "QPZLIEFNR=:QPZLIEFNR,"
                + "QPZLAFDL=:QPZLAFDL,"
                + "QPZLADS=:QPZLADS,"
                + "QPZFKZ=:QPZFKZ,"
                + "QPZAUFBER=:QPZAUFBER,"
                + "QPZDRTRB=:QPZDRTRB,"
                + "QPZFILLER=:QPZFILLER"
                + " WHERE  QPZMANDANT=:QPZMANDANT AND QPZART=:QPZART AND QPZVAR=:QPZVAR AND QPZPNRKRS=:QPZPNRKRS AND QPZPLFDNR=:QPZPLFDNR ";
            or1.Parameters.Add("QPZMANDANT", OracleType.NVarChar).Value = dwData["QPZMANDANT"].ToString();
            or1.Parameters.Add("QPZARTST", OracleType.NVarChar).Value = dwData["QPZARTST"].ToString();
            or1.Parameters.Add("QPZKUNDNR", OracleType.NVarChar).Value = dwData["QPZKUNDNR"].ToString();
            or1.Parameters.Add("QPZWERK", OracleType.NVarChar).Value = dwData["QPZWERK"].ToString();
            or1.Parameters.Add("QPZABT", OracleType.NVarChar).Value = dwData["QPZABT"].ToString();
            or1.Parameters.Add("QPZART", OracleType.NVarChar).Value = dwData["QPZART"].ToString();
            or1.Parameters.Add("QPZVAR", OracleType.NVarChar).Value = dwData["QPZVAR"].ToString();
            or1.Parameters.Add("QPZPNRKRS", OracleType.NVarChar).Value = dwData["QPZPNRKRS"].ToString();
            or1.Parameters.Add("QPZPLFDNR", OracleType.NVarChar).Value = dwData["QPZPLFDNR"].ToString();
            or1.Parameters.Add("QPZAENZL", OracleType.NVarChar).Value = dwData["QPZAENZL"].ToString();
            or1.Parameters.Add("QPZAENB", OracleType.NVarChar).Value = dwData["QPZAENB"].ToString();
            or1.Parameters.Add("QPZAEND", OracleType.NVarChar).Value = dwData["QPZAEND"].ToString();
            or1.Parameters.Add("QPZNEUB", OracleType.NVarChar).Value = dwData["QPZNEUB"].ToString();
            or1.Parameters.Add("QPZNEUD", OracleType.NVarChar).Value = dwData["QPZNEUD"].ToString();
            or1.Parameters.Add("QPZSPEZIF", OracleType.NVarChar).Value = dwData["QPZSPEZIF"].ToString();
            or1.Parameters.Add("QPZSPSTA", OracleType.NVarChar).Value = dwData["QPZSPSTA"].ToString();
            or1.Parameters.Add("QPZSPGRD", OracleType.NVarChar).Value = dwData["QPZSPGRD"].ToString();
            or1.Parameters.Add("QPZZUSTAND", OracleType.NVarChar).Value = dwData["QPZZUSTAND"].ToString();
            or1.Parameters.Add("QPZPKUNDNR", OracleType.NVarChar).Value = dwData["QPZPKUNDNR"].ToString();
            or1.Parameters.Add("QPZPADRSL", OracleType.NVarChar).Value = dwData["QPZPADRSL"].ToString();
            or1.Parameters.Add("QPZLIEFNR", OracleType.NVarChar).Value = dwData["QPZLIEFNR"].ToString();
            or1.Parameters.Add("QPZLAFDL", OracleType.NVarChar).Value = dwData["QPZLAFDL"].ToString();
            or1.Parameters.Add("QPZLADS", OracleType.NVarChar).Value = dwData["QPZLADS"].ToString();
            or1.Parameters.Add("QPZFKZ", OracleType.NVarChar).Value = dwData["QPZFKZ"].ToString();
            or1.Parameters.Add("QPZAUFBER", OracleType.NVarChar).Value = dwData["QPZAUFBER"].ToString();
            or1.Parameters.Add("QPZDRTRB", OracleType.NVarChar).Value = dwData["QPZDRTRB"].ToString();
            or1.Parameters.Add("QPZFILLER", OracleType.NVarChar).Value = dwData["QPZFILLER"].ToString();
            Connect2Proxy(or1);
        }
    }
}
